package com.craigcmiller.cmtetris.core;


/**
 * Specific block type
 * @author craig
 */
public class ReverseZBlock extends Block
{
	private boolean horizontal;
	
	
	/**
	 * Construct the block
	 * @param b
	 */
	public ReverseZBlock(Board b)
	{
		super(b);
		
		this.horizontal=true;
	}
	
	
	/**
	 * Create the initial version of the block
	 */
	@Override
	protected void build()
	{
		cells.add(new BlockCell(board.getWidth()/2, 0));
		cells.add(new BlockCell(board.getWidth()/2+1, 0));
		cells.add(new BlockCell(board.getWidth()/2-1, 1));
		cells.add(new BlockCell(board.getWidth()/2, 1));
	}
	
	
	/**
	 * Rotate the block
	 */
	@Override
	public void rotate()
	{
		if (horizontal) {
			if (this.isCellMoveLegal(2, 2, 0) && this.isCellMoveLegal(1, 0, 2)) {
				this.moveCell(2, 2, 0);
				this.moveCell(1, 0, 2);
				
				horizontal=false;
			}
		} else {
			if (this.isCellMoveLegal(2, -2, 0) && this.isCellMoveLegal(1, 0, -2)) {
				this.moveCell(2, -2, 0);
				this.moveCell(1, 0, -2);
				
				horizontal=true;
			}
		}
	}
}
